package com.itfreer.xjmh.security;

import com.itfreer.form.api.PageInfo;
import com.itfreer.utils.ResponseEntity;
import com.itfreer.xjmh.security.entity.SecurityPersonEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.itfreer.form.api.BaseDao;
import com.itfreer.bpm.api.BaseWorkFlowServiceImp;
import com.itfreer.xjmh.security.entity.SecurityEquipmentEntity;
import com.itfreer.xjmh.security.dao.SecurityEquipmentDao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 定义安保设备实现类
 */
@Component
public class SecurityEquipmentServiceImp extends BaseWorkFlowServiceImp<SecurityEquipmentEntity> implements SecurityEquipmentService {

	@Autowired
	private SecurityEquipmentDao dao;

	@Override
	protected BaseDao<SecurityEquipmentEntity> getDao() {
		return dao;
	}
	
	/**
	 * 获取流程状态字段
	 * 
	 * @return
	 */
	@Override
	protected String getBpmStateFieldName() {
		return "bpmState";
	}

	/**
	 * 是否为租户实体对象
	 */
	@Override
	protected boolean isTenant() {
		return true;
	}

	/**
	 * 获取租户字段名称 用于SAAS下数据管理
	 */
	@Override
	protected String getTenantFieldName() {
		return "tenantID";
	}


	@Override
	public ResponseEntity getAllData() {
		PageInfo pageInfo = new PageInfo();
		Map<String, Integer> map = new HashMap<>();
		map.put("id",0);
		pageInfo.setOrder(map);
		pageInfo.setPageIndex(1);
		pageInfo.setPageSize(99999);
		List<SecurityEquipmentEntity> person = getEntitys(pageInfo);
		Map<String,Long> person1 = person.stream().collect(Collectors.groupingBy(k -> k.getEquipmentTypeName() == null? "EquipmentTypeName" : k.getEquipmentTypeName(),
				Collectors.counting()));
		return new ResponseEntity(person1);
	}
}
